{include file="public/header" /}
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
    .editor {
        width:100%;
        min-height: 300px;
    }
</style>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('authGroup/index')}">角色管理</a></li>
        <li class="active"><a href="javascript:;">编辑角色</a></li>
    </ul>
    <form class="form-horizontal js-ajax-form margin-top-20">
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>角色名称</label>
            <div class="col-md-6 col-sm-10">
                <input type="text" class="form-control" name="name" value="{$info['name']|default=''}">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label"><span class="form-required">*</span>角色描述</label>
            <div class="col-md-6 col-sm-10">
                <textarea type="text" class="form-control"  name="description">{$info['description']|default=''}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label">状态</label>
            <div class="col-md-6 col-sm-10">
                <label class="radio-inline">
                    <input type="radio" name="status" {if condition="$info['status'] eq '1'"}checked{/if} value="1"> 开启 </label>
                <label class="radio-inline">
                    <input type="radio" name="status" {if condition="$info['status'] eq '0'"}checked{/if} value="0"> 禁用 </label>
            </div>
        </div>
        <div class="form-group">
            <div class="col-sm-offset-2 col-sm-10">
                <input type="hidden" name="id" value="{$info['id']}" />
                <input type="hidden" name="action" value="{$params['action']}" />
                <button type="button" class="btn btn-primary js-ajax-submit">提交</button>
            </div>
        </div>
    </form>
</div>
<script src="{$static}js/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $(".js-ajax-submit").click(function () {
            var name = $("input[name=name]").val();
            var description = $("textarea[name=description]").val();
            if(name === "" || name === undefined) {
                layer.alert("请输入角色名称");
                return false;
            }
            if(description === "" || description === undefined) {
                layer.alert("请输入角色描述");
                return false;
            }
            $.ajax({
                url: "{:url('authGroup/operateAjax')}",
                type: "POST",
                data: $(".js-ajax-form").serialize(),
                dataType: 'json',
                async: false,
                success: function (res) {
                    if(res.errorCode === 200){
                        layer.confirm(res.message, {
                            btn:['确认','取消'],
                            success:function(){
                                this.enterEsc = function (event) {
                                    if (event.keyCode === 13) {
                                        $(".layui-layer-btn0").click();
                                        return false;
                                    }
                                };
                                $(document).on('keydown', this.enterEsc);

                                $(".layui-layer-btn0").on("click",function() {
                                    window.location.href = "{:url('authGroup/index')}";
                                    return false
                                })
                            },
                            end:function(){
                                $(document).off('keydown',this.enterEsc);
                            }
                        });
                    }else{
                        layer.alert(res.message, {
                            title: '提示',
                            icon: 2
                        });
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
